<?php 
/**
*售后数据分析
*/
require("./include/init.php");
$address=$_REQUEST['address'];
//连接数据库
$mysql=mysql::getIns();
date_default_timezone_set('Asia/Shanghai');
//今天的时间戳
$t = time();
$start = mktime(0,0,0,date("m",$t),date("d",$t),date("Y",$t));
$end = mktime(23,59,59,date("m",$t),date("d",$t),date("Y",$t));

//统计今天售后区人数
$sql="select count(*) from alldev where whitelist <> '1' and timestamp > $start and timestamp < $end and area<>'展厅区' and area<>'销售区' and shop='". $address ."'";
$nowservice=$mysql->getOne($sql);

//昨天的时间戳
$t = time();
$start = mktime(0,0,0,date("m",$t),date("d",$t),date("Y",$t))-24*3600;
$end = mktime(23,59,59,date("m",$t),date("d",$t),date("Y",$t))-24*3600;

//昨天售后区人数
$sql="select count(*) from alldev where whitelist <> '1' and timestamp > $start and timestamp < $end and area<>'展厅区' and area<>'销售区' and shop='". $address ."'";
$yesdservice=$mysql->getOne($sql);




//获取本周周一的时间
$one=strtotime('-1 monday', time())+24*3600*7;
// echo $one . '<br />';
// echo date('Y-m-d H:i:s',$one);
// exit;
//获取本周周二时间
$two=strtotime('-1 monday', time())+24*3600*8;

//获取本周周三时间
$three=strtotime('-1 monday', time())+24*3600*9;

//获取本周周四时间
$four=strtotime('-1 monday', time())+24*3600*10;

//获取本周周五时间
$five=strtotime('-1 monday', time())+24*3600*11;

//获取本周周六时间
$six=strtotime('-1 monday', time())+24*3600*12;

//获取本周周日时间
$seven=strtotime('-1 monday', time())+24*3600*13;
// echo date('Y-m-d H:i:s',$seven);

//获取下周周一
$nowone=strtotime('-1 monday', time())+24*3600*14;
// echo date('Y-m-d H:i:s',$nowone);


//统计本周周一进店量
$sql="select count(*) from alldev where whitelist <> '1' and timestamp >= $one and timestamp < $two and area<>'展厅区' and area<>'销售区' and shop='". $address ."'";
$onejk=$mysql->getOne($sql);
//统计本周周二进店量
$sql="select count(*) from alldev where whitelist <> '1' and timestamp >= $two and timestamp < $three and area<>'展厅区' and area<>'销售区' and shop='". $address ."'";
$twojk=$mysql->getOne($sql);
//统计本周周三进店量
$sql="select count(*) from alldev where whitelist <> '1' and timestamp >= $three and timestamp < $four and area<>'展厅区' and area<>'销售区' and shop='". $address ."'";
$threejk=$mysql->getOne($sql);
//统计本周周四进店量
$sql="select count(*) from alldev where whitelist <> '1' and timestamp >= $four and timestamp < $five and area<>'展厅区' and area<>'销售区' and shop='". $address ."'";
$fourjk=$mysql->getOne($sql);
//统计本周周五进店量
$sql="select count(*) from alldev where whitelist <> '1' and timestamp >= $five and timestamp < $six and area<>'展厅区' and area<>'销售区' and shop='". $address ."'";
$fivejk=$mysql->getOne($sql);
// echo $fivejk;
// exit;
//统计本周周六进店量
$sql="select count(*) from alldev where whitelist <> '1' and timestamp >= $six and timestamp < $seven and area<>'展厅区' and area<>'销售区' and shop='". $address ."'";
// $sql="select * from alldev where whitelist <> '1' and timestamp >= $six and timestamp < $seven and shop='". $address ."'";
$sixjk=$mysql->getOne($sql);
// echo $sixjk;
// exit;
//统计本周周日进店量
$sql="select count(*) from alldev where whitelist <> '1' and timestamp >= $seven and timestamp < $nowone and area<>'展厅区' and area<>'销售区' and shop='". $address ."'";
$sevenjk=$mysql->getOne($sql);




/**************************
获取本月第一个周一的时间

**********************/
$year=date('Y',time());
$month=date('m',time());
$base_time = strtotime ( "{$year}-{$month}-01" );
$base_w = date ( "w", $base_time );

if($base_w == '1'){
  //刚好是星期一
  $first = $base_time;
}else{
  //不是星期一
  //找到上个星期天是几月几号
  $last_sun = date ( "Y-m-d", strtotime("-$base_w day", $base_time));
  //在上个星期天的基础上 加8天
  $first = strtotime ( "+8 day", strtotime ( $last_sun ) );
}
//第二个周一的时间
$second=$first+7*24*3600;
// echo date('Y-m-d H:i:s',$second);
// exit;
//第三个时间戳
$third=$second+7*24*3600;
// echo date('Y-m-d H:i:s',$third);
// exit;
//第四个时间戳
$fourth=$third+7*24*3600;
// echo date('Y-m-d H:i:s',$fourth);
// exit;
//下周一时间戳
$fifth=$fourth+7*24*3600;
// echo date('Y-m-d H:i:s',$third);
// exit;


//获取这个月第一周的人数
$sql="select count(*) from alldev where whitelist <> '1' and timestamp >= $first and timestamp < $second and area<>'展厅区' and area<>'销售区' and shop='". $address ."'";
$firstjk=$mysql->getOne($sql);
// echo $firstjk;
// exit;

//获取这个月第二周的人数
$sql="select count(*) from alldev where whitelist <> '1' and timestamp >= $second and timestamp < $third and area<>'展厅区' and area<>'销售区' and shop='". $address ."'";
$secondjk=$mysql->getOne($sql);
// echo $secondjk;
// exit;
$bak=$secondjk;

//获取这个月第三周的人数
$sql="select count(*) from alldev where whitelist <> '1' and timestamp >= $third and timestamp < $fourth and area<>'展厅区' and area<>'销售区' and shop='". $address ."'";
$thirdjk=$mysql->getOne($sql);
// echo $thirdjk;
// exit;

//获取这个月第四周的人数
$sql="select count(*) from alldev where whitelist <> '1' and timestamp >= $fourth and timestamp < $fifth and area<>'展厅区' and area<>'销售区' and shop='". $address ."'";
$fourthjk=$mysql->getOne($sql);




//获取第一季度开始时间戳
$firstmonth =mktime(0,0,0,1,1,date('Y',time()));

//获取第二季度开始时间
$secondmonth =mktime(0,0,0,4,1,date('Y',time()));
// echo date('Y-m-d H:i:s',$secondmonth);

//获取第三季度开始时间
$thirdmonth =mktime(0,0,0,7,1,date('Y',time()));
// echo date('Y-m-d H:i:s',$thirdmonth);

//获取第四季度开始时间
$fourthmonth =mktime(0,0,0,10,1,date('Y',time()));
// echo date('Y-m-d H:i:s',$fourthmonth);

//获取明年第一季度开始时间
$firstmonths =mktime(0,0,0,1,1,date('Y',time())+1);
// echo date('Y-m-d H:i:s',$firstmonths);



//获取第一季度的人数
$sql="select count(*) from alldev where whitelist <> '1' and timestamp >= $firstmonth and timestamp < $secondmonth and area<>'展厅区' and area<>'销售区' and shop='". $address ."'";
$firstmonth=$mysql->getOne($sql);
// echo $firstmonth;
// exit;

//获取第二季度的人数
$sql="select count(*) from alldev where whitelist <> '1' and timestamp >= $secondmonth and timestamp < $thirdmonth and area<>'展厅区' and area<>'销售区' and shop='". $address ."'";
$secondmonth=$mysql->getOne($sql);

//获取第三季度的人数
$sql="select count(*) from alldev where whitelist <> '1' and timestamp >= $thirdmonth and timestamp < $fourthmonth and area<>'展厅区' and area<>'销售区' and shop='". $address ."'";
$thirdmonth=$mysql->getOne($sql);
// echo $thirdmonth;
// exit;


//获取第四季度的人数
$sql="select count(*) from alldev where whitelist <> '1' and timestamp >= $fourthmonth and timestamp < $firstmonths and area<>'展厅区' and area<>'销售区' and shop='". $address ."'";
$fourthmonth=$mysql->getOne($sql);

// echo $fourthmonth;
// exit;







/****************************************


		4s店的wifi登录率


****************************************/


//总人数为今天累计人数
$maxtime=time();
$mintime=$maxtime-10*60;



//统计当前在线人数    (在线人数为当前时间的十分钟之前到现在的人数)


$maxtime=time();
$mintime=$maxtime-10*60;
// echo $maxtime . '<br />';
// echo $mintime;
$sql="select count(*) from alldev where whitelist <> '1' and timestamp > $mintime and timestamp < $maxtime and shop='". $address ."'";
$allnow=$mysql->getOne($sql);


//统计登陆人数
$sql="select count(*) from alldev where whitelist <> '1' and isOL=1 and timestamp > $mintime and timestamp < $maxtime and shop='" . $address ."'";
$denglu=$mysql->getOne($sql);
// echo $login;

// echo $allday;
// exit;
// echo $denglu;
$loginnum=ceil(($denglu/$allnow)*100);
// echo $loginnum;
// exit;

//未登录
$nologinnum=100-$loginnum;









require(ROOT . 'view/iwocar5/4S_ServiceDirector.html');
 ?>
